package com.linkai.JVM;

/**
 * @Description: 类加载器
 * @Author: 林凯
 * @Date: 2021/10/20 13:53
 */
public class Car {

    public int age;

    public static void main(String[] args) {
        // 类是模版，对象是具体的
//        Class<Car> carClass = Car.class;

        Car car1 = new Car();
        Car car2 = new Car();
        Car car3 = new Car();

        car1.age = 18;
        car2.age = 21;
        car3.age = 22;

        System.out.println(car1.hashCode());
        System.out.println(car2.hashCode());
        System.out.println(car3.hashCode());

        // 获取反射对象（模板），这3个class对象是同一个
        Class<? extends Car> aClass1 = car1.getClass();
        Class<? extends Car> aClass2 = car2.getClass();
        Class<? extends Car> aClass3 = car3.getClass();

        System.out.println(aClass1.hashCode());
        System.out.println(aClass2.hashCode());
        System.out.println(aClass3.hashCode());

        ClassLoader classLoader = aClass1.getClassLoader();
        System.out.println(classLoader);    // AppClassLoader
        ClassLoader parent = classLoader.getParent();
        System.out.println(parent);     // ExtClassLoader
        ClassLoader parent1 = parent.getParent();
        System.out.println(parent1);    // null 1.不存在 2.获取不到 rt.jar

    }
}
